package com.aspose.cells;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

public final class DateTime implements Comparable<Object> {
   private static final int[] d = new int[]{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
   private static final int[] e = new int[]{0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366};
   public static final DateTime a = new DateTime(0L, 0L);
   public static final DateTime b = new DateTime(3155378975999999999L, 0L);
   private long f;
   // $FF: synthetic field
   static final boolean c = !DateTime.class.desiredAssertionStatus();

   public String a(String var1, com.aspose.cells.b.a.c.za var2) {
      return com.aspose.cells.a.c.zp.a(this, c(var1), var2);
   }

   public String a() {
      if (Locale.getDefault().equals(Locale.US)) {
         return this.b("HH:mm:ss");
      } else {
         DateFormat var1 = DateFormat.getTimeInstance();
         var1.setTimeZone(TimeZone.getTimeZone("GMT"));
         return var1.format(this.j());
      }
   }

   public static DateTime a(String var0, String var1, com.aspose.cells.b.a.c.za var2) throws Exception {
      SimpleDateFormat var3 = new SimpleDateFormat(c(var1), var2.h());
      var3.setTimeZone(TimeZone.getTimeZone("GMT"));
      Date var4 = var3.parse(var0);
      return new DateTime(var4);
   }

   public static DateTime b(String var0, com.aspose.cells.b.a.c.za var1) throws Exception {
      if (var0 == null) {
         throw new IllegalArgumentException("String dateTime can not be null.");
      } else {
         Object var2 = null;
         Object var3 = null;
         com.aspose.cells.a.b.a.za var4 = com.aspose.cells.a.b.a.zc.a(var0, var1, new com.aspose.cells.a.b.a.zd(), (DateTime)var2, (com.aspose.cells.a.b.a.zb)var3);
         if (!var4.a()) {
            throw new Exception(var0 + " cannot be parsed.");
         } else {
            return var4.b();
         }
      }
   }

   public static DateTime a(String var0) throws Exception {
      return b(var0, com.aspose.cells.b.a.c.za.a());
   }

   public DateTime() {
      this.f = 0L;
   }

   public DateTime(long ticks) {
      if (ticks >= 0L && ticks <= 3155378975999999999L) {
         this.f = ticks;
      } else {
         throw new IndexOutOfBoundsException("ticks");
      }
   }

   private static DateTime d(long var0) {
      DateTime var2 = new DateTime();
      var2.f = var0;
      return var2;
   }

   public DateTime(long ticks, long kind) {
      if (ticks >= 0L && ticks <= 3155378975999999999L) {
         if (kind >= 0L && kind <= 2L) {
            this.f = ticks | kind << 62;
         } else {
            throw new IllegalArgumentException("Argument_InvalidDateTimeKind");
         }
      } else {
         throw new IndexOutOfBoundsException("ArgumentOutOfRange_DateTimeBadTicks");
      }
   }

   public DateTime(int year, int month, int day) {
      this.f = a(year, month, day);
   }

   public DateTime(int year, int month, int day, int hour, int minute, int second) {
      this.f = a(year, month, day) + b(hour, minute, second);
   }

   public DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond) {
      long var8 = a(year, month, day) + b(hour, minute, second);
      if (millisecond >= 0 && millisecond < 1000) {
         var8 += (long)millisecond * 10000L;
         if (var8 >= 0L && var8 <= 3155378975999999999L) {
            this.f = var8;
         } else {
            throw new IllegalArgumentException("Arg_DateTimeRange");
         }
      } else {
         throw new IndexOutOfBoundsException("millisecond");
      }
   }

   public DateTime(Date date) {
      this(b(e(date.getTime())), 1L);
   }

   public DateTime(Calendar cld) {
      this(b(a(cld)), 1L);
   }

   public Date toDate() {
      long var1 = this.i();
      return new Date(var1 - (long)TimeZone.getDefault().getOffset(var1));
   }

   public Calendar toCalendar() {
      Calendar var1 = Calendar.getInstance();
      long var2 = this.i();
      var1.setTimeInMillis(var2 - (long)TimeZone.getDefault().getOffset(var2));
      return var1;
   }

   private static long e(long var0) {
      return var0 + (long)TimeZone.getDefault().getOffset(var0);
   }

   private static long a(Calendar var0) {
      long var1 = var0.getTimeInMillis();
      return var1 + (long)var0.getTimeZone().getOffset(var1);
   }

   private long l() {
      return this.f & 4611686018427387903L;
   }

   private long m() {
      return this.f & -4611686018427387904L;
   }

   public DateTime a(com.aspose.cells.b.a.zk var1) {
      return this.a(var1.a());
   }

   private DateTime a(double var1, int var3) {
      long var4 = (long)(var1 * (double)var3 + (var1 >= 0.0D ? 0.5D : -0.5D));
      if (var4 > -315537897600000L && var4 < 315537897600000L) {
         return this.a(var4 * 10000L);
      } else {
         throw new IndexOutOfBoundsException("value");
      }
   }

   public DateTime addDays(double value) {
      return this.a(value, 86400000);
   }

   public DateTime addHours(double value) {
      return this.a(value, 3600000);
   }

   public DateTime addMilliseconds(double value) {
      return this.a(value, 1);
   }

   public DateTime addMinutes(double value) {
      return this.a(value, 60000);
   }

   public DateTime addMonths(int months) {
      if (months >= -120000 && months <= 120000) {
         int var2 = this.b(0);
         int var3 = this.b(2);
         int var4 = this.b(3);
         int var5 = var3 - 1 + months;
         if (var5 >= 0) {
            var3 = var5 % 12 + 1;
            var2 += var5 / 12;
         } else {
            var3 = 12 + (var5 + 1) % 12;
            var2 += (var5 - 11) / 12;
         }

         if (var2 >= 1 && var2 <= 9999) {
            int var6 = a(var2, var3);
            if (var4 > var6) {
               var4 = var6;
            }

            return d(a(var2, var3, var4) + this.l() % 864000000000L | this.m());
         } else {
            throw new IndexOutOfBoundsException("months");
         }
      } else {
         throw new IndexOutOfBoundsException("months");
      }
   }

   public DateTime addSeconds(double value) {
      return this.a(value, 1000);
   }

   public DateTime a(long var1) {
      long var3 = this.l();
      if (var1 <= 3155378975999999999L - var3 && var1 >= 0L - var3) {
         return d(var3 + var1 | this.m());
      } else {
         throw new IndexOutOfBoundsException("value");
      }
   }

   public DateTime addYears(int value) {
      if (value >= -10000 && value <= 10000) {
         return this.addMonths(value * 12);
      } else {
         throw new IndexOutOfBoundsException("years");
      }
   }

   public int compareTo(Object value) {
      if (value == null) {
         return 1;
      } else if (!(value instanceof DateTime)) {
         throw new IllegalArgumentException("Arg_MustBeDateTime");
      } else {
         long var2 = ((DateTime)value).l();
         long var4 = this.l();
         if (var4 > var2) {
            return 1;
         } else {
            return var4 < var2 ? -1 : 0;
         }
      }
   }

   public int compareTo(DateTime value) {
      long var2 = value.l();
      long var4 = this.l();
      if (var4 > var2) {
         return 1;
      } else {
         return var4 < var2 ? -1 : 0;
      }
   }

   private static long a(int var0, int var1, int var2) {
      if (var0 >= 1 && var0 <= 9999 && var1 >= 1 && var1 <= 12) {
         int[] var3 = a(var0) ? e : d;
         if (var2 >= 1 && var2 <= var3[var1] - var3[var1 - 1]) {
            int var4 = var0 - 1;
            int var5 = var4 * 365 + var4 / 4 - var4 / 100 + var4 / 400 + var3[var1 - 1] + var2 - 1;
            return (long)var5 * 864000000000L;
         }
      }

      throw new IndexOutOfBoundsException("ArgumentOutOfRange_BadYearMonthDay");
   }

   private static long b(int var0, int var1, int var2) {
      if (var0 >= 0 && var0 < 24 && var1 >= 0 && var1 < 60 && var2 >= 0 && var2 < 60) {
         return com.aspose.cells.b.a.zk.a(var0, var1, var2);
      } else {
         throw new IndexOutOfBoundsException("ArgumentOutOfRange_BadHourMinuteSecond");
      }
   }

   public static int a(int var0, int var1) {
      if (var1 >= 1 && var1 <= 12) {
         int[] var2 = a(var0) ? e : d;
         return var2[var1] - var2[var1 - 1];
      } else {
         throw new IndexOutOfBoundsException("month");
      }
   }

   static long a(double var0) {
      if (var0 < 2958466.0D && var0 > -657435.0D) {
         long var2 = (long)(var0 * 8.64E7D + (var0 >= 0.0D ? 0.5D : -0.5D));
         if (var2 < 0L) {
            var2 -= var2 % 86400000L * 2L;
         }

         var2 += 59926435200000L;
         if (var2 >= 0L && var2 < 315537897600000L) {
            return var2 * 10000L;
         } else {
            throw new IllegalArgumentException("Arg_OleAutDateScale");
         }
      } else {
         throw new IllegalArgumentException("Arg_OleAutDateInvalid");
      }
   }

   public int hashCode() {
      long var1 = this.l();
      return (int)var1 ^ (int)(var1 >> 32);
   }

   public boolean equals(Object value) {
      return value instanceof DateTime && a(this, (DateTime)value);
   }

   public static boolean a(DateTime var0, DateTime var1) {
      if (var0 == var1) {
         return true;
      } else {
         return var0 != null && var1 != null && var0.l() == var1.l();
      }
   }

   public static DateTime b(double var0) {
      return new DateTime(a(var0), 0L);
   }

   public DateTime b() {
      long var1 = this.l();
      return d(var1 - var1 % 864000000000L | this.m());
   }

   private int b(int var1) {
      long var2 = this.l();
      int var4 = (int)(var2 / 864000000000L);
      int var5 = var4 / 146097;
      var4 -= var5 * 146097;
      int var6 = var4 / '躬';
      if (var6 == 4) {
         var6 = 3;
      }

      var4 -= var6 * '躬';
      int var7 = var4 / 1461;
      var4 -= var7 * 1461;
      int var8 = var4 / 365;
      if (var8 == 4) {
         var8 = 3;
      }

      if (var1 == 0) {
         return var5 * 400 + var6 * 100 + var7 * 4 + var8 + 1;
      } else {
         var4 -= var8 * 365;
         if (var1 == 1) {
            return var4 + 1;
         } else {
            boolean var9 = var8 == 3 && (var7 != 24 || var6 == 3);
            int[] var10 = var9 ? e : d;

            int var11;
            for(var11 = var4 >> 6; var4 >= var10[var11]; ++var11) {
               ;
            }

            return var1 == 2 ? var11 : var4 - var10[var11 - 1] + 1;
         }
      }
   }

   public int getDay() {
      return this.b(3);
   }

   public int getDayOfWeek() {
      return (int)((this.l() / 864000000000L + 1L) % 7L);
   }

   public int getDayOfYear() {
      return this.b(1);
   }

   public int getHour() {
      return (int)(this.l() / 36000000000L % 24L);
   }

   public long c() {
      long var1 = this.m();
      if (var1 == 0L) {
         return 0L;
      } else {
         return var1 == 4611686018427387904L ? 1L : 2L;
      }
   }

   public int getMillisecond() {
      return (int)(this.l() / 10000L % 1000L);
   }

   public int getMinute() {
      return (int)(this.l() / 600000000L % 60L);
   }

   public int getMonth() {
      return this.b(2);
   }

   public static DateTime getNow() {
      return d().toLocalTime();
   }

   public static DateTime d() {
      long var0 = System.currentTimeMillis();
      long var2 = b(var0);
      return d(var2 | 4611686018427387904L);
   }

   public int getSecond() {
      return (int)(this.l() / 10000000L % 60L);
   }

   public long e() {
      return this.l();
   }

   public com.aspose.cells.b.a.zk f() {
      return new com.aspose.cells.b.a.zk(this.l() % 864000000000L);
   }

   public static DateTime g() {
      return getNow().b();
   }

   public int getYear() {
      return this.b(0);
   }

   public static boolean a(int var0) {
      if (var0 >= 1 && var0 <= 9999) {
         return var0 % 4 == 0 && (var0 % 100 != 0 || var0 % 400 == 0);
      } else {
         throw new IndexOutOfBoundsException("year");
      }
   }

   public com.aspose.cells.b.a.zk a(DateTime var1) {
      return new com.aspose.cells.b.a.zk(this.l() - var1.l());
   }

   private static double f(long var0) {
      if (var0 == 0L) {
         return 0.0D;
      } else {
         if (var0 < 864000000000L) {
            var0 += 599264352000000000L;
         }

         if (var0 < 31241376000000000L) {
            throw new IllegalStateException("Arg_OleAutDateInvalid");
         } else {
            long var2 = (var0 - 599264352000000000L) / 10000L;
            if (var2 < 0L) {
               long var4 = var2 % 86400000L;
               if (var4 != 0L) {
                  var2 -= (86400000L + var4) * 2L;
               }
            }

            return (double)var2 / 8.64E7D;
         }
      }
   }

   public double h() {
      return f(this.l());
   }

   public DateTime toLocalTime() {
      if (this.c() == 2L) {
         return this;
      } else {
         long var1 = this.i();
         long var3 = (long)TimeZone.getDefault().getOffset(var1);
         long var5 = b(var1 + var3);
         if (var5 > 3155378975999999999L) {
            return new DateTime(3155378975999999999L, 2L);
         } else {
            return var5 < 0L ? new DateTime(0L, 2L) : new DateTime(var5, 2L);
         }
      }
   }

   public long i() {
      return this.l() / 10000L - 62135596800000L;
   }

   public Date j() {
      long var1;
      if (a.equals(this)) {
         var1 = -62135769599766L;
      } else {
         var1 = this.i();
      }

      return new Date(var1);
   }

   public static long b(long var0) {
      long var2 = 62135596800000L + var0;
      if (var2 < 0L) {
         var2 = 0L;
      }

      return var2 * 10000L;
   }

   public String toString() {
      return com.aspose.cells.a.c.zp.a(this, "yyyy-MM-dd'T'HH:mm:ss");
   }

   public String k() {
      if (Locale.getDefault().equals(Locale.US)) {
         return this.b("MM/dd/yyyy");
      } else {
         DateFormat var1 = DateFormat.getDateInstance();
         var1.setTimeZone(TimeZone.getTimeZone("GMT"));
         return var1.format(this.j());
      }
   }

   public String b(String var1) {
      var1 = c(var1);
      return com.aspose.cells.a.c.zp.a(this, var1);
   }

   private static String c(String var0) {
      if (var0 == null) {
         var0 = "G";
      }

      if (var0.length() == 1) {
         char var1 = var0.charAt(0);
         if (var1 == 'd') {
            var0 = "MM/dd/yy";
         } else if (var1 == 'D') {
            var0 = "EEEE, MMMM dd, yyyy";
         } else if (var1 == 'f') {
            var0 = "EEEE, MMMM dd, yyyy HH:mm";
         } else if (var1 == 'F') {
            var0 = "EEEE, MMMM dd, yyyy HH:mm:ss";
         } else if (var1 == 'g') {
            var0 = "MM/dd/yy HH:mm";
         } else if (var1 == 'G') {
            var0 = "MM/dd/yy HH:mm:ss";
         } else if (var1 != 'm' && var1 != 'M') {
            if (var1 != 'r' && var1 != 'R') {
               if (var1 == 's') {
                  var0 = "yyyy-MM-dd'T'HH:mm:ss";
               } else if (var1 == 't') {
                  var0 = "h:mm a";
               } else if (var1 == 'T') {
                  var0 = "HH:mm:ss";
               } else if (var1 == 'u') {
                  var0 = "yyyy-MM-dd HH:mm:ss'Z'";
               } else if (var1 == 'U') {
                  var0 = "EEEE, dd MMMM yyyy HH:mm:ss";
               } else if (var1 == 'y' || var1 == 'Y') {
                  var0 = "yyyy MMMM";
               }
            } else {
               var0 = "EEE, dd MMM yyyy HH:mm:ss z";
            }
         } else {
            var0 = "MMMM dd";
         }
      } else {
         var0 = var0.replace("tt", "a");
         var0 = var0.replace("dddd", "EEEE");
         var0 = var0.replace("ddd", "EEE");
         var0 = var0.replace("Y", "y");
         var0 = var0.replace("f", "S");
         var0 = var0.replace("\\T", "'T'");
         var0 = var0.replace("\\Z", "'Z'");
      }

      return var0;
   }

   public DateTime toUniversalTime() {
      if (this.c() == 1L) {
         return this;
      } else {
         long var1 = this.i();
         long var3 = (long)TimeZone.getDefault().getOffset(var1);
         long var5 = b(var1 - var3);
         if (var5 > 3155378975999999999L) {
            return new DateTime(3155378975999999999L, 1L);
         } else {
            return var5 < 0L ? new DateTime(0L, 1L) : new DateTime(var5, 1L);
         }
      }
   }

   private void g(long var1) {
      this.f |= var1;
   }

   public void c(long var1) {
      if (var1 == 0L) {
         this.g(0L);
      } else if (var1 == 1L) {
         this.g(4611686018427387904L);
      } else {
         this.g(Long.MIN_VALUE);
      }

   }
}
